<template>
  <div>
    <Wrap>
      <div slot="main_wrap">
          <div class="form-inline form-find ng-pristine ng-valid">
            <div class="form-group">
								<label>项目名称：</label>
						</div>
						<div class="form-group" style="min-width:200px">
              <!-- <avue-input-tree v-model="form2" placeholder="请选择内容" :append-to-body="false" type="tree" :dic="dic"></avue-input-tree> -->
               <el-select class="form-control " v-model="form1" :popper-append-to-body="false">
                  <el-option value="0" label="广东省税务局"><span>广东省税务局</span></el-option>
                </el-select>
            </div>
            <div class="form-group">
              <label>建筑名称：</label>
              <div class="form-group-control">
                 <el-select  v-model="form2" :popper-append-to-body="false">
                  <el-option value="0" label="潭村办公楼"><span>潭村办公楼</span></el-option>
                </el-select>
              </div>
            </div>
            <div class="form-group">
              <label>楼层位置：</label>
              <div class="form-group-control">
                 <el-select v-model="position"
                        placeholder="请选择楼层位置"
                        clearable filterable>
                    <el-option v-for="item in optionsLc"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
              </div>
            </div>
            <div class="form-group">
              <label>仪表产品：</label>
              <div class="form-group-control">
                 <el-select v-model="meterProdName"
                      placeholder="请选择仪表产品"
                      @change="changeYb"
                      clearable>
                  <el-option v-for="item in optionsLy"
                          :key="item.id"
                          :label="item.label"
                          :value="item.value">
                  </el-option>
              </el-select>
              </div>
            </div>
            <div class="form-group">
              <label>仪表名称：</label>
              <div class="form-group-control">
                 <el-select v-model="meterName"
                      placeholder="请选择仪表名称"
                      clearable filterable>
                  <el-option v-for="item in optionsYb"
                          :key="item.id"
                          :label="item.deviceName"
                          :value="item.deviceName">
                  </el-option>
              </el-select>
              </div>
            </div>
             <div class="form-group">
              <label>开始时间：</label>
              <div class="form-group-control">
                 <el-date-picker
                    v-model="params.startDate"
                    value-format="yyyy-MM-dd"
                    :type="typedate">
                  </el-date-picker>
              </div>
            </div>
             <div class="form-group">
              <label>结束时间：</label>
              <div class="form-group-control">
                 <el-date-picker
                    v-model="params.endDate"
                    value-format="yyyy-MM-dd"
                    :type="typedate">
                  </el-date-picker>
              </div>
            </div>
            <div class="form-group">
               <a class="btn btn-sm btn-primary" role="button" @click="getData">搜索</a>
              <!-- <a class="btn btn-sm btn-primary" role="button" ng-click="go('platform.realtimereadingtable')" access-field="goMeterReadingList">总体耗能</a>
              <a class="btn btn-sm btn-primary" role="button" ng-click="toHourlyEnergy()" access-field="goHourlyenergytrend">导出</a> -->
            </div>
         </div>
        <avue-crud ref="crud"
            :page.sync="page"
            :data="tableData"
            :permission="permissionList"
            :table-loading="tableLoading"
            :option="tableOption"
            @on-load="getList"
            @search-change="searchChange"
            @refresh-change="refreshChange"
            @size-change="sizeChange"
            @current-change="currentChange">
            <!-- <template slot="search">
                <div class="form-group">
                  <label>项目名称：</label>
              </div>
              <div class="form-group" style="min-width:200px">
                <avue-input-tree v-model="form2" placeholder="请选择内容" :append-to-body="false" type="tree" :dic="dic"></avue-input-tree>
              </div>
              <div class="form-group">
                <label>建筑名称：</label>
                <div class="form-group-control">
                  <el-select v-model="select1" class="form-control select-stuct" :popper-append-to-body="false">
                    <el-option value="1" label="汕头市税务局大楼（东区）" >汕头市税务局大楼（东区）</el-option>
                    <el-option value="2" label="汕头市税务局大楼（西区）">汕头市税务局大楼（西区）</el-option>
                  </el-select>
                </div>
              </div>
              <div class="form-group">
              <label>用能仪表：</label>
              <div class="form-group-control">
                 <avue-input-tree v-model="select6" placeholder="请选择内容" :append-to-body="false" type="tree" :dic="dic"></avue-input-tree>
              </div>
            </div>
            </template> -->
            <template slot="footer">
                <div class="total-block">
                    <span>总用量：{{totalYl}}</span>
                    <!-- <span>总费用： {{totalPrice}}</span> -->
                </div>
            </template>
        </avue-crud>
      </div>
    </Wrap>
  </div>
</template>

<script type="text/ecmascript-6">
import Wrap from '@/components/energy-wrap'
import {getMonthFirstDate, getCurrentDate} from '@/util/date'
import {tableOption} from '@/const/crud/energy/month'
import { remote } from "@/api/admin/dict";
import { meterMonth, meterMonthSum, selectDropList } from '@/api/energy/energy'
export default {
  components: {
    Wrap
  },
  data () {
    return {
      select1: '1',
      form2:'0',
      form1: '0',
      optionsLy: [],
      optionsYb: [],
      optionsLc: [],
       meterName: '',
      meterProdName: '',
      position: '',
      select6: '',
       options: [],
      typedate: 'date',
      searchForm: {
        // dateRange: [getMonthFirstDate('year'), getCurrentDate('year')]
        dateRange: []
      },
      dic:[{
          label:'广东省税务局',
          value:0,
          // children:[{
          //    label:'选项3',
          //    value:2
          // },{
          //    label:'选项4',
          //    value:3
          // }]
        // },{
        //   label:'选项2',
        //   value:1
        }],
      params: {
        startDate: getMonthFirstDate('year'),
        endDate: getCurrentDate('year'),
        energyUseType: '1'
      },
      totalYl: '',
      totalPrice: '',
      tableData: [],
      page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption
    }
  },
  computed: {
      permissionList() {
          return {
              addBtn: false,
              delBtn: false,
              editBtn: false
          };
      }
  },
  created() {
    this.init()
  },
  methods: {
     init() {
          remote('energy_equipment_type').then(response => {
              this.optionsLy = response.data.data
          })
          remote('energy_device_position').then(response => {
              this.optionsLc = response.data.data
          })
      },
      changeYb(value) {
        var field_lastValue = this.findObject(this.tableOption.column,'lastValue')
        var field_thisValue = this.findObject(this.tableOption.column,'thisValue')
        var field_used = this.findObject(this.tableOption.column,'used')
        if (value) {
          if (value === '水表') {
            field_lastValue.label = '上次读数 （吨）'
            field_thisValue.label = '本次读数（吨）'
            field_used.label = '用量 （吨）'
          } else {
            field_lastValue.label = '上次读数 （kW.h）'
            field_thisValue.label = '本次读数 （kW.h）'
            field_used.label = '用量 （kW.h）'
          }
          this.meterName = ''
          selectDropList({equipmentType: value}).then(response => {
            this.optionsYb = response.data.data
          })
        } else {
          this.meterName = ''
          this.meterProdName = ''
          this.optionsYb = []
          field_lastValue.label = '上次读数 （kW.h）'
          field_thisValue.label = '本次读数 （kW.h）'
          field_used.label = '用量 （kW.h）'
        }
      },
      getList(page, params) {
          this.tableLoading = true
           if (this.searchForm.dateRange) {
                this.searchForm.startDate = this.searchForm.dateRange[0];
                this.searchForm.endDate = this.searchForm.dateRange[1];
          }
          if (this.meterName) {
            this.params.meterName = this.meterName
          } else {
            this.params.meterName = ''
          }
           if (this.position) {
            this.params.position = this.position
          } else {
            this.params.position = ''
          }
          if (this.meterProdName) {
            this.params.meterProdName = this.meterProdName
          } else {
            this.params.meterProdName = ''
          }
          meterMonth(Object.assign({
              current: page.currentPage,
              size: page.pageSize
          }, params, this.params )).then(response => {
              response.data.data.records.map(item => {
                item.lastValue = item.lastValue.toFixed(2)
                item.thisValue = item.thisValue.toFixed(2)
                item.used = item.used.toFixed(2)
              })
              this.tableData = response.data.data.records
              this.page.total = response.data.data.total
              this.tableLoading = false
          }).catch(() => {
              this.tableLoading=false
          })
          meterMonthSum(Object.assign({}, this.params)).then(response => {
            this.totalYl = response.data.data.toFixed(2)
          })
      },
      getData() {
        this.page.currentPage = 1
        this.getList(this.page, this.params)
      },
      sizeChange(pageSize){
          this.page.pageSize = pageSize
      },
      currentChange(current){
          this.page.currentPage = current
      },
      searchChange(form, done) {
          this.searchForm = form
          this.page.currentPage = 1
          this.getList(this.page, form)
          done()
      },
      refreshChange() {
          this.getList(this.page)
      }
  }
}
</script>

<style lang="scss" scoped>
.total-block{
  margin-top: 10px;
  width: 100%;
  color:#fff;
  text-align: center;
  span{
    margin-right: 20px;
  }
}
.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
    padding: 8px;
    line-height: 1.42857143;
    vertical-align: middle;
    border: 1px solid rgb(10, 57, 98);
}
.form-find {
    padding: 20px;
    background-color: #081325;
    box-shadow: inset 0px 1px 13px 0px #1AABF3;
    border: solid 1px rgba(15, 80, 111, 0.55);
    margin-bottom: 10px;
   .form-group {
        margin-right: 3px;
        margin-bottom: 3px;
    }
}
.reading-row {
    line-height: 25px;
    margin-right: 2px;
    white-space: nowrap;
    text-overflow: ellipsis;
    border-bottom: 1px solid #0a91ef;
    overflow: hidden;
    .el-icon-circle-check {
      color: green;
    }
    .icon {
        font-size: 23px;
        vertical-align: middle;
    }
}
.outline-border {
    border: 1px solid #ddd;
    color:#fff;
    padding: 5px;
    .total-count {
        color: #0371F7;
        text-decoration: underline;
        font-weight: bold;
    }
    .abnormal-rate {
        color: red;
        font-weight: bold;
    }
}
.list-content{
  height: 475px;
  overflow-y: auto;
  margin-top: 10px;
  .device-reading {
    float: left;
  }
}
.form-inline label {
    margin-right: 7px;
}
.form-group-control {
    display: inline-block;
    vertical-align: middle;
}
.nav-tabs {
    margin-bottom: 15px;
    &>li.active,&>li:hover {
      background-color: transparent;
    }
}

.form-group {
    display: inline-block;
    vertical-align: middle;
}

</style>
